home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 4 / Macwelt DVD 4.cdr / Entwickler / Mac-OS / oxygen / samples / docbook / xsl / html / graphics.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-09-09  |  18.8 KB  |  529 lines  |  [□□□□/□□□□]

  1. graphics.xslHûπ¢tÚπ¢tÚÅÅœ<?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.                 xmlns:xlink="http://www.w3.org/1999/xlink"
  4.                 xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
  5.                 xmlns:xtext="com.nwalsh.xalan.Text"
  6.                 xmlns:lxslt="http://xml.apache.org/xslt"
  7.                 exclude-result-prefixes="xlink stext xtext lxslt"
  8.                 extension-element-prefixes="stext xtext"
  9.                 version='1.0'>
  10.  
  11. <!-- ********************************************************************
  12.      $Id: graphics.xsl,v 1.1 2002/05/29 09:55:49 dan Exp $
  13.      ********************************************************************
  14.  
  15.      This file is part of the XSL DocBook Stylesheet distribution.
  16.      See ../README or http://nwalsh.com/docbook/xsl/ for copyright
  17.      and other information.
  18.  
  19.      Contributors:
  20.      Colin Paul Adams, <colin@colina.demon.co.uk>
  21.  
  22.      ******************************************************************** -->
  23.  
  24. <lxslt:component prefix="xtext"
  25.                  elements="insertfile"/>
  26.  
  27. <!-- ==================================================================== -->
  28. <!-- Graphic format tests for the HTML backend -->
  29.  
  30. <xsl:template name="is.graphic.format">
  31.   <xsl:param name="format"></xsl:param>
  32.   <xsl:if test="$format = 'PNG'
  33.                 or $format = 'JPG'
  34.                 or $format = 'JPEG'
  35.                 or $format = 'linespecific'
  36.                 or $format = 'GIF'
  37.                 or $format = 'GIF87a'
  38.                 or $format = 'GIF89a'
  39.                 or $format = 'BMP'">1</xsl:if>
  40. </xsl:template>
  41.  
  42. <xsl:template name="is.graphic.extension">
  43.   <xsl:param name="ext"></xsl:param>
  44.   <xsl:if test="$ext = 'png'
  45.                 or $ext = 'jpeg'
  46.                 or $ext = 'jpg'
  47.                 or $ext = 'avi'
  48.                 or $ext = 'mpg'
  49.                 or $ext = 'mpeg'
  50.                 or $ext = 'qt'
  51.                 or $ext = 'gif'
  52.                 or $ext = 'bmp'">1</xsl:if>
  53. </xsl:template>
  54.  
  55. <!-- ==================================================================== -->
  56.  
  57. <xsl:template match="screenshot">
  58.   <div class="{name(.)}">
  59.     <xsl:apply-templates/>
  60.   </div>
  61. </xsl:template>
  62.  
  63. <xsl:template match="screeninfo">
  64. </xsl:template>
  65.  
  66. <!-- ==================================================================== -->
  67.  
  68. <xsl:template name="process.image">
  69.   <!-- When this template is called, the current node should be  -->
  70.   <!-- a graphic, inlinegraphic, imagedata, or videodata. All    -->
  71.   <!-- those elements have the same set of attributes, so we can -->
  72.   <!-- handle them all in one place.                             -->
  73.   <xsl:param name="tag" select="'img'"/>
  74.   <xsl:param name="alt"/>
  75.   <xsl:param name="longdesc"/>
  76.  
  77.   <xsl:variable name="filename">
  78.     <xsl:choose>
  79.       <xsl:when test="local-name(.) = 'graphic'
  80.                       or local-name(.) = 'inlinegraphic'">
  81.         <!-- handle legacy graphic and inlinegraphic by new template --> 
  82.         <xsl:call-template name="mediaobject.filename">
  83.           <xsl:with-param name="object" select="."/>
  84.         </xsl:call-template>
  85.       </xsl:when>
  86.       <xsl:otherwise>
  87.         <!-- imagedata, videodata, audiodata -->
  88.         <xsl:call-template name="mediaobject.filename">
  89.           <xsl:with-param name="object" select=".."/>
  90.         </xsl:call-template>
  91.       </xsl:otherwise>
  92.     </xsl:choose>
  93.   </xsl:variable>
  94.  
  95.   <xsl:variable name="width">
  96.     <xsl:choose>
  97.       <xsl:when test="@scale"><xsl:value-of select="@scale"/>%</xsl:when>
  98.       <xsl:when test="@width">
  99.         <xsl:variable name="w-magnitude">
  100.           <xsl:call-template name="length-magnitude">
  101.             <xsl:with-param name="length" select="@width"/>
  102.           </xsl:call-template>
  103.         </xsl:variable>
  104.         <xsl:variable name="w-units">
  105.           <xsl:call-template name="length-units">
  106.             <xsl:with-param name="length" select="@width"/>
  107.             <xsl:with-param name="default.units" select="'px'"/>
  108.           </xsl:call-template>
  109.         </xsl:variable>
  110.  
  111.         <xsl:choose>
  112.           <xsl:when test="$w-units = '%'">
  113.             <xsl:value-of select="@width"/>
  114.           </xsl:when>
  115.           <xsl:when test="$w-units = 'cm'">
  116.             <xsl:value-of select="round(($w-magnitude div 2.54) * $pixels.per.inch)"/>
  117.           </xsl:when>
  118.           <xsl:when test="$w-units = 'mm'">
  119.             <xsl:value-of select="round(($w-magnitude div 25.4) * $pixels.per.inch)"/>
  120.           </xsl:when>
  121.           <xsl:when test="$w-units = 'in'">
  122.             <xsl:value-of select="round($w-magnitude * $pixels.per.inch)"/>
  123.           </xsl:when>
  124.           <xsl:when test="$w-units = 'pt'">
  125.             <xsl:value-of select="round(($w-magnitude div 72) * $pixels.per.inch)"/>
  126.           </xsl:when>
  127.           <xsl:when test="$w-units = 'pc'">
  128.             <xsl:value-of select="round(($w-magnitude div 6) * $pixels.per.inch)"/>
  129.           </xsl:when>
  130.           <xsl:when test="$w-units = 'px'">
  131.             <xsl:value-of select="$w-magnitude"/>
  132.           </xsl:when>
  133.           <xsl:when test="$w-units = 'em'">
  134.             <xsl:message>
  135.               <xsl:text>Relative units (ems) are not supported on widths.  </xsl:text>
  136.               <xsl:text>Using 12pt/em.</xsl:text>
  137.             </xsl:message>
  138.             <xsl:value-of select="round((($w-magnitude * 12) div 72) * $pixels.per.inch)"/>
  139.           </xsl:when>
  140.           <xsl:otherwise>
  141.             <xsl:message>
  142.               <xsl:text>Unrecognized unit given for width: </xsl:text>
  143.               <xsl:value-of select="$w-units"/>
  144.               <xsl:text>. Treating as px.</xsl:text>
  145.               <xsl:value-of select="$w-magnitude"/>
  146.             </xsl:message>
  147.           </xsl:otherwise>
  148.         </xsl:choose>
  149.       </xsl:when>
  150.       <xsl:otherwise></xsl:otherwise>
  151.     </xsl:choose>
  152.   </xsl:variable>
  153.  
  154.   <xsl:variable name="height">
  155.     <xsl:choose>
  156.       <xsl:when test="@scale"></xsl:when>
  157.       <xsl:when test="@depth">
  158.         <xsl:variable name="d-magnitude">
  159.           <xsl:call-template name="length-magnitude">
  160.             <xsl:with-param name="length" select="@depth"/>
  161.           </xsl:call-template>
  162.         </xsl:variable>
  163.         <xsl:variable name="d-units">
  164.           <xsl:call-template name="length-units">
  165.             <xsl:with-param name="length" select="@depth"/>
  166.             <xsl:with-param name="default.units" select="'px'"/>
  167.           </xsl:call-template>
  168.         </xsl:variable>
  169.  
  170.         <xsl:choose>
  171.           <xsl:when test="$d-units = '%'">
  172.             <xsl:value-of select="@depth"/>
  173.           </xsl:when>
  174.           <xsl:when test="$d-units = 'cm'">
  175.             <xsl:value-of select="round(($d-magnitude div 2.54) * $pixels.per.inch)"/>
  176.           </xsl:when>
  177.           <xsl:when test="$d-units = 'mm'">
  178.             <xsl:value-of select="round(($d-magnitude div 25.4) * $pixels.per.inch)"/>
  179.           </xsl:when>
  180.           <xsl:when test="$d-units = 'in'">
  181.             <xsl:value-of select="round($d-magnitude * $pixels.per.inch)"/>
  182.           </xsl:when>
  183.           <xsl:when test="$d-units = 'pt'">
  184.             <xsl:value-of select="round(($d-magnitude div 72) * $pixels.per.inch)"/>
  185.           </xsl:when>
  186.           <xsl:when test="$d-units = 'pc'">
  187.             <xsl:value-of select="round(($d-magnitude div 6) * $pixels.per.inch)"/>
  188.           </xsl:when>
  189.           <xsl:when test="$d-units = 'px'">
  190.             <xsl:value-of select="$d-magnitude"/>
  191.           </xsl:when>
  192.           <xsl:when test="$d-units = 'em'">
  193.             <xsl:message>
  194.               <xsl:text>Relative units (ems) are not supported on depths.  </xsl:text>
  195.               <xsl:text>Using 12pt/em.</xsl:text>
  196.             </xsl:message>
  197.             <xsl:value-of select="round((($d-magnitude * 12) div 72) * $pixels.per.inch)"/>
  198.           </xsl:when>
  199.           <xsl:otherwise>
  200.             <xsl:message>
  201.               <xsl:text>Unrecognized unit given for depth: </xsl:text>
  202.               <xsl:value-of select="$d-units"/>
  203.               <xsl:text>. Treating as px.</xsl:text>
  204.               <xsl:value-of select="$d-magnitude"/>
  205.             </xsl:message>
  206.           </xsl:otherwise>
  207.         </xsl:choose>
  208.       </xsl:when>
  209.       <xsl:otherwise></xsl:otherwise>
  210.     </xsl:choose>
  211.   </xsl:variable>
  212.  
  213.   <xsl:variable name="align">
  214.     <xsl:value-of select="@align"/>
  215.   </xsl:variable>
  216.  
  217.   <xsl:element name="{$tag}">
  218.     <xsl:attribute name="src">
  219.       <xsl:value-of select="$filename"/>
  220.     </xsl:attribute>
  221.     <xsl:if test="$align != ''">
  222.       <xsl:attribute name="align">
  223.         <xsl:value-of select="$align"/>
  224.       </xsl:attribute>
  225.     </xsl:if>
  226.     <xsl:if test="$height != ''">
  227.       <xsl:attribute name="height">
  228.         <xsl:value-of select="$height"/>
  229.       </xsl:attribute>
  230.     </xsl:if>
  231.     <xsl:if test="$width != ''">
  232.       <xsl:attribute name="width">
  233.         <xsl:value-of select="$width"/>
  234.       </xsl:attribute>
  235.     </xsl:if>
  236.     <xsl:if test="$alt != ''">
  237.       <xsl:attribute name="alt">
  238.         <xsl:value-of select="$alt"/>
  239.       </xsl:attribute>
  240.     </xsl:if>
  241.     <xsl:if test="$longdesc != ''">
  242.       <xsl:attribute name="longdesc">
  243.         <xsl:value-of select="$longdesc"/>
  244.       </xsl:attribute>
  245.     </xsl:if>
  246.   </xsl:element>
  247. </xsl:template>
  248.  
  249. <!-- ==================================================================== -->
  250.  
  251. <xsl:template match="graphic">
  252.   <xsl:choose>
  253.     <xsl:when test="../inlineequation">
  254.       <xsl:call-template name="anchor"/>
  255.       <xsl:call-template name="process.image"/>
  256.     </xsl:when>
  257.     <xsl:otherwise>
  258.       <p>
  259.         <xsl:call-template name="anchor"/>
  260.         <xsl:call-template name="process.image"/>
  261.       </p>
  262.     </xsl:otherwise>
  263.   </xsl:choose>
  264. </xsl:template>
  265.  
  266. <xsl:template match="inlinegraphic">
  267.   <xsl:variable name="filename">
  268.     <xsl:choose>
  269.       <xsl:when test="@entityref">
  270.         <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  271.       </xsl:when>
  272.       <xsl:otherwise>
  273.         <xsl:value-of select="@fileref"/>
  274.       </xsl:otherwise>
  275.     </xsl:choose>
  276.   </xsl:variable>
  277.  
  278.   <xsl:if test="@id">
  279.     <a name="{@id}"/>
  280.   </xsl:if>
  281.  
  282.   <xsl:choose>
  283.     <xsl:when test="@format='linespecific'">
  284.       <xsl:choose>
  285.         <xsl:when test="$use.extensions != '0'
  286.                         and $textinsert.extension != '0'">
  287.           <xsl:choose>
  288.             <xsl:when test="element-available('stext:insertfile')">
  289.               <stext:insertfile href="{$filename}"/>
  290.             </xsl:when>
  291.             <xsl:when test="element-available('xtext:insertfile')">
  292.               <xtext:insertfile href="{$filename}"/>
  293.             </xsl:when>
  294.             <xsl:otherwise>
  295.               <xsl:message terminate="yes">
  296.                 <xsl:text>No insertfile extension available.</xsl:text>
  297.               </xsl:message>
  298.             </xsl:otherwise>
  299.           </xsl:choose>
  300.         </xsl:when>
  301.         <xsl:otherwise>
  302.           <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
  303.              href="{$filename}"/>
  304.         </xsl:otherwise>
  305.       </xsl:choose>
  306.     </xsl:when>
  307.     <xsl:otherwise>
  308.       <xsl:call-template name="process.image"/>
  309.     </xsl:otherwise>
  310.   </xsl:choose>
  311. </xsl:template>
  312.  
  313. <!-- ==================================================================== -->
  314.  
  315. <xsl:template match="mediaobject|mediaobjectco">
  316.   <div class="{name(.)}">
  317.     <xsl:if test="@id">
  318.       <a name="{@id}"/>
  319.     </xsl:if>
  320.     <xsl:call-template name="select.mediaobject"/>
  321.     <xsl:apply-templates select="caption"/>
  322.   </div>
  323. </xsl:template>
  324.  
  325. <xsl:template match="inlinemediaobject">
  326.   <span class="{name(.)}">
  327.     <xsl:if test="@id">
  328.       <a name="{@id}"/>
  329.     </xsl:if>
  330.     <xsl:call-template name="select.mediaobject"/>
  331.   </span>
  332. </xsl:template>
  333.  
  334. <xsl:template match="programlisting/inlinemediaobject
  335.                      |screen/inlinemediaobject" priority="2">
  336.   <!-- the additional span causes problems in some cases -->
  337.   <xsl:call-template name="select.mediaobject"/>
  338. </xsl:template>
  339.  
  340. <!-- ==================================================================== -->
  341.  
  342. <xsl:template match="imageobjectco">
  343.   <xsl:if test="@id">
  344.     <a name="{@id}"/>
  345.   </xsl:if>
  346.   <xsl:apply-templates select="imageobject"/>
  347.   <xsl:apply-templates select="calloutlist"/>
  348. </xsl:template>
  349.  
  350. <xsl:template match="imageobject">
  351.   <xsl:apply-templates select="imagedata"/>
  352. </xsl:template>
  353.  
  354. <xsl:template match="imagedata">
  355.   <xsl:variable name="filename">
  356.     <xsl:call-template name="mediaobject.filename">
  357.       <xsl:with-param name="object" select=".."/>
  358.     </xsl:call-template>
  359.   </xsl:variable>
  360.  
  361.   <xsl:choose>
  362.     <xsl:when test="@format='linespecific'">
  363.       <xsl:choose>
  364.         <xsl:when test="$use.extensions != '0'
  365.                         and $textinsert.extension != '0'">
  366.           <xsl:choose>
  367.             <xsl:when test="element-available('stext:insertfile')">
  368.               <stext:insertfile href="{$filename}"/>
  369.             </xsl:when>
  370.             <xsl:when test="element-available('xtext:insertfile')">
  371.               <xtext:insertfile href="{$filename}"/>
  372.             </xsl:when>
  373.             <xsl:otherwise>
  374.               <xsl:message terminate="yes">
  375.                 <xsl:text>No insertfile extension available.</xsl:text>
  376.               </xsl:message>
  377.             </xsl:otherwise>
  378.           </xsl:choose>
  379.         </xsl:when>
  380.         <xsl:otherwise>
  381.           <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
  382.              href="{$filename}"/>
  383.         </xsl:otherwise>
  384.       </xsl:choose>
  385.     </xsl:when>
  386.     <xsl:otherwise>
  387.       <xsl:variable name="longdesc.uri">
  388.         <xsl:call-template name="longdesc.uri">
  389.           <xsl:with-param name="mediaobject"
  390.                           select="ancestor::imageobject/parent::*"/>
  391.         </xsl:call-template>
  392.       </xsl:variable>
  393.  
  394.       <xsl:call-template name="process.image">
  395.         <xsl:with-param name="alt">
  396.           <xsl:apply-templates select="(../../textobject[not(@role) or @role!='tex']/phrase)[1]"/>
  397.         </xsl:with-param>
  398.         <xsl:with-param name="longdesc">
  399.           <xsl:call-template name="write.longdesc">
  400.             <xsl:with-param name="mediaobject"
  401.                             select="ancestor::imageobject/parent::*"/>
  402.           </xsl:call-template>
  403.         </xsl:with-param>
  404.       </xsl:call-template>
  405.  
  406.       <xsl:if test="$html.longdesc != 0 and $html.longdesc.link != 0
  407.                     and ancestor::imageobject/parent::*/textobject[not(phrase)]">
  408.         <xsl:call-template name="longdesc.link">
  409.           <xsl:with-param name="longdesc.uri" select="$longdesc.uri"/>
  410.         </xsl:call-template>
  411.       </xsl:if>
  412.     </xsl:otherwise>
  413.   </xsl:choose>
  414. </xsl:template>
  415.  
  416. <!-- ==================================================================== -->
  417.  
  418. <xsl:template name="longdesc.uri">
  419.   <xsl:param name="mediaobject" select="."/>
  420.  
  421.   <xsl:if test="$html.longdesc">
  422.     <xsl:if test="$mediaobject/textobject[not(phrase)]">
  423.       <xsl:variable name="image-id">
  424.         <xsl:call-template name="object.id">
  425.           <xsl:with-param name="object" select="$mediaobject"/>
  426.         </xsl:call-template>
  427.       </xsl:variable>
  428.       <xsl:variable name="filename">
  429.         <xsl:call-template name="make-relative-filename">
  430.           <xsl:with-param name="base.dir" select="$base.dir"/>
  431.           <xsl:with-param name="base.name"
  432.                           select="concat('ld-',$image-id,$html.ext)"/>
  433.         </xsl:call-template>
  434.       </xsl:variable>
  435.  
  436.       <xsl:value-of select="$filename"/>
  437.     </xsl:if>
  438.   </xsl:if>
  439. </xsl:template>
  440.  
  441. <xsl:template name="write.longdesc">
  442.   <xsl:param name="mediaobject" select="."/>
  443.   <xsl:if test="$html.longdesc != 0 and $mediaobject/textobject[not(phrase)]">
  444.     <xsl:variable name="filename">
  445.       <xsl:call-template name="longdesc.uri">
  446.         <xsl:with-param name="mediaobject" select="$mediaobject"/>
  447.       </xsl:call-template>
  448.     </xsl:variable>
  449.  
  450.     <xsl:value-of select="$filename"/>
  451.  
  452.     <xsl:call-template name="write.chunk">
  453.       <xsl:with-param name="filename" select="$filename"/>
  454.       <xsl:with-param name="quiet" select="$chunk.quietly"/>
  455.       <xsl:with-param name="content">
  456.         <html>
  457.           <head>
  458.             <title>Long Description</title>
  459.           </head>
  460.           <body>
  461.             <xsl:call-template name="body.attributes"/>
  462.             <xsl:for-each select="$mediaobject/textobject[not(phrase)]">
  463.               <xsl:apply-templates select="./*"/>
  464.             </xsl:for-each>
  465.           </body>
  466.         </html>
  467.       </xsl:with-param>
  468.     </xsl:call-template>
  469.   </xsl:if>
  470. </xsl:template>
  471.  
  472. <xsl:template name="longdesc.link">
  473.   <xsl:param name="longdesc.uri" select="''"/>
  474.   <div class="longdesc-link" align="right">
  475.     <br clear="all"/>
  476.     <span style="font-size: 8pt;">
  477.       <xsl:text>[</xsl:text>
  478.       <a href="{$longdesc.uri}" target="longdesc">D</a>
  479.       <xsl:text>]</xsl:text>
  480.     </span>
  481.   </div>
  482. </xsl:template>
  483.  
  484. <!-- ==================================================================== -->
  485.  
  486. <xsl:template match="videoobject">
  487.   <xsl:apply-templates select="videodata"/>
  488. </xsl:template>
  489.  
  490. <xsl:template match="videodata">
  491.   <xsl:call-template name="process.image">
  492.     <xsl:with-param name="tag" select="'embed'"/>
  493.     <xsl:with-param name="alt">
  494.       <xsl:apply-templates select="(../../textobject/phrase)[1]"/>
  495.     </xsl:with-param>
  496.   </xsl:call-template>
  497. </xsl:template>
  498.  
  499. <!-- ==================================================================== -->
  500.  
  501. <xsl:template match="audioobject">
  502.   <xsl:apply-templates select="audiodata"/>
  503. </xsl:template>
  504.  
  505. <xsl:template match="audiodata">
  506.   <xsl:call-template name="process.image">
  507.     <xsl:with-param name="tag" select="'embed'"/>
  508.     <xsl:with-param name="alt">
  509.       <xsl:apply-templates select="(../../textobject/phrase)[1]"/>
  510.     </xsl:with-param>
  511.   </xsl:call-template>
  512. </xsl:template>
  513.  
  514. <!-- ==================================================================== -->
  515.  
  516. <xsl:template match="textobject">
  517.   <xsl:apply-templates/>
  518. </xsl:template>
  519.  
  520. <!-- ==================================================================== -->
  521.  
  522. <xsl:template match="caption">
  523.   <div class="{name(.)}">
  524.     <xsl:apply-templates/>
  525.   </div>
  526. </xsl:template>
  527.  
  528. </xsl:stylesheet>
  529. This resource fork intentionally left blank   ˇˇ